package com.xr.quartz;

import com.xr.utils.QiNiuUtils;
import com.xr.utils.RedisConstant;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;


public class CleanImgJob {

    @Autowired
    private JedisPool jedisPool;

    public void doClear(){
        System.out.println("调用了："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        //1.获取redis的链接
        Jedis jedis = jedisPool.getResource();
        //2.计算2个set集合的差集 所有七牛图片-保存到数据库
        //3.需要删除的图片
        Set<String> diff = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        //4.调用七牛云删除
        QiNiuUtils.removeFiles(diff.toArray(new String[]{}));
        //5.删除Redis上的图片，因为俩边的图片已经同步了
        jedis.del(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);

    }

}
